import 'package:fish_redux/fish_redux.dart';
import 'package:wowhy/models/admin_user_info.dart';

import 'action.dart';
import 'state.dart';

Reducer<AdminUserItemState> buildReducer() {
  return asReducer(
    <Object, Reducer<AdminUserItemState>>{
      AdminUserItemAction.edit: _edit,
    },
  );
}

AdminUserItemState _edit(AdminUserItemState state, Action action) {
  final AdminUserInfo payload = action.payload as AdminUserInfo;

  if (payload?.id == state.model?.id) {
    return state.clone()..model = payload;
  }

  return state;
}
